import os
from config import data_path

index = 0  # start from 1


class FileSource:
    def __init__(self, **kwargs):
        self.filter = lambda x: x  # do nothing
        self.paths = []
        self.frs = []
        if kwargs.get('filename'):
            self.open(kwargs.get('filename'))

    def open(self, filename):
        self.paths.append(filename)
        self.frs.append(open(filename))

    def __iter__(self):
        global index
        for fr in self.frs:
            index += 1
            l = os.path.getsize(fr.name)
            while fr.tell() < l:
                line = fr.readline()
                yield self.filter(line.strip())


class LabelGenerator:
    def __init__(self):
        self.labels = [0, -1, 1]  # none, pos, neg

    def __iter__(self):
        global index
        while True:
            yield self.labels[index]

if __name__ == '__main__':
    f = FileSource(filename=data_path('1.txt'))
    f.open(data_path('2.txt'))
    l = LabelGenerator()
    j = 0
    for i in f:
        print(i)
        j += 1
        if j > 10:
            break
    j = 0
    for i in f:
        print (i)
        j += 1
        if j > 10:
            break
